import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_author/utils/rouces_util.dart';

import '../../../utils/utils.dart';

class ConnectSelectDialog extends StatefulWidget {
  Function connectCallBack;
  Function imageCallBack;
  ConnectSelectDialog({
    Key? key,
    required this.connectCallBack,
    required this.imageCallBack,
  }) : super(key: key);

  @override
  State<ConnectSelectDialog> createState() => _ConnectSelectDialogState();
}

class _ConnectSelectDialogState extends State<ConnectSelectDialog> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 255.w,
      width: Get.width,
      child: Stack(
        children: [
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              buildButton(
                "连麦鉴宝",
                "ic_connect_live_lt",
                () {
                  widget.connectCallBack();
                  Get.back();
                },
              ),
              SizedBox(
                height: 20.w,
              ),
              buildButton(
                "发图鉴宝",
                "ic_connect_image_lt",
                () {
                  Get.back();
                  widget.imageCallBack();
                },
                needSubTitle: true,
              ),
            ],
          ),
          Positioned(
            child: GestureDetector(
              child: Container(
                child: Image.asset(
                  RoucesUtil.getAssets('ic_close_gray'),
                  width: 14.w,
                  height: 14.w,
                  color: Colors.white,
                ),
              ),
              onTap: () {
                Get.back();
              },
            ),
            right: 14.w,
            top: 14.w,
          ),
        ],
      ),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(12.w),
          topRight: Radius.circular(12.w),
        ),
        gradient: LinearGradient(
          colors: [
            rgba(178, 207, 135, 1),
            rgba(68, 169, 73, 1),
          ],
          begin: Alignment.centerLeft,
          end: Alignment.centerRight,
        ),
      ),
    );
  }

  buildButton(
    String title,
    String image,
    GestureTapCallback onTap, {
    bool needSubTitle: false,
  }) {
    return GestureDetector(
      child: Container(
        height: 60.w,
        margin: EdgeInsets.symmetric(
          horizontal: 12.w,
        ),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(30.w),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                RoucesUtil.getAssetsIcon(image, 24),
                SizedBox(
                  width: 10.w,
                ),
                Text(
                  title,
                  style: TextStyle(
                    fontSize: 16.sp,
                    color: rgba(51, 51, 51, 1),
                  ),
                )
              ],
            ),
            if (needSubTitle)
              Container(
                margin: EdgeInsets.only(
                  top: 4.w,
                ),
                child: Text(
                  "发送宝贝图片，主播将在直播间对您的宝贝进行讲解",
                  style: TextStyle(
                    fontSize: 12.sp,
                    color: rgba(153, 153, 153, 1),
                  ),
                ),
              ),
          ],
        ),
      ),
      onTap: onTap,
    );
  }
}
